import java.util.LinkedList;
import java.util.Queue;

/**
 * @Author: YCKOKO
 * @Date: 2023-05-15
 * @Time:11:08
 * @Description:
 */
public class demo2 {
    public boolean chkParenthesis(String A, int n) {
        // write code here
        if (n % 2 != 0 || A.charAt(0) != '(') {
            return false;
        }
        Queue<Character> queue = new LinkedList<>();
        queue.offer(A.charAt(0));
        for (int i = 1; i < A.length(); i++) {
            char ch = A.charAt(i);
            if (ch == ')') {
                queue.poll();
            } else if (ch == '(') {
                queue.offer(ch);
            } else {
                return false;
            }
        }
        return queue.isEmpty();
    }
}
